package sg.techstudio.suntec.util;

import java.util.Collection;

public class CustomTagUtil {
	public static final int PACKAGE_GOLD = 1;
	public static final int PACKAGE_SILVER = 2;
	public static final int PACKAGE_CHC = 3;
	
	public static boolean contains(Collection<?> coll, Object o) {
		return coll!=null && coll.contains(o);
	}
	
	public static boolean containsAny(Collection<?> coll, Object[] objs) {
		if(coll==null || objs==null)
			return false;
		for(Object o: objs) {
			if(coll.contains(o)) {
				return true;
			}
		}
		return false;
	}
	
	public static String packageType(int packageType) {
		switch(packageType) {
		case PACKAGE_GOLD: 
			return "Gold";
		case PACKAGE_SILVER:
			return "Silver";
		default:
			return "CHC";
		}
	}
	
	public static String humanReadableByteCount(long bytes) {
		return humanReadableByteCount(bytes, true);
	}
	
	public static String humanReadableByteCount(long bytes, boolean si) {
	    int unit = si ? 1000 : 1024;
	    if (bytes < unit) return bytes + " B";
	    int exp = (int) (Math.log(bytes) / Math.log(unit));
	    String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp-1) + (si ? "" : "i");
	    return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
	}
}
